﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using HT.Future.Application;
using HT.Future.Common;
using HT.Future.Entities;
using HT.Future.IService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;

namespace HT.Future.TxApi.Controllers
{
    [ApiVersion("1.0")]
    [Authorize]
    [Route("api/[controller]")]
    public class BusinessController : BaseController
    {
        private readonly IBusinessService _service;

        public BusinessController(IMapper mapper, IBusinessService service) : base(mapper)
        {
            this._service = service;
        }

        /// <summary>
        /// 获取微信用户绑定的商户列表
        /// </summary>
        /// <returns></returns>
        public async Task<ApiResult<List<Business>>> GetBusinesses()
        {
            var userId = UserId;
            return null;
        }

        /// <summary>
        /// 微信用户绑定商户信息
        /// </summary>
        /// <param name="business"></param>
        /// <returns></returns>
        [HttpPost("bind")]
        public async Task<ApiResult<Business>> BindBusiness([FromBody] Business business)
        {
            return await _service.CreateBusinessAsync(UserId, business);
        }

        /// <summary>
        /// 解除绑定
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<ApiResult> RemoveBind(int id)
        {
            await _service.DeleteBusinessAsync(UserId, id);
            return Content("解绑成功");
        }

    }
}